package com.ruoyi.jproom.service.impl;

import com.ruoyi.jproom.mapper.AppUserMapper;
import com.ruoyi.jproom.service.AppUserService;
import com.ruoyi.jproom.utils.BaseResult;
import com.ruoyi.jproom.utils.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author zeo
 * @explain 用户操作服务实现类
 * @date 2020/8/8 14:22
 */
@Service
public class AppUserServiceImpl implements AppUserService {

    @Autowired
    AppUserMapper appUserMapper;

    @Override
    public BaseResult insertFollow(String userId, String followId) {
        if (appUserMapper.insertFollow(userId, followId) > 0) {
            return BaseResult.build(ResultEnum.SUCCESS);
        } else {
            return BaseResult.build(ResultEnum.FAILURE);
        }
    }

    @Override
    public BaseResult cancelFollow(String userId, String followId) {
        if (appUserMapper.cancelFollow(userId, followId) > 0) {
            return BaseResult.build(ResultEnum.SUCCESS);
        } else {
            return BaseResult.build(ResultEnum.FAILURE);
        }
    }

    @Override
    public BaseResult findFollowCount(String userId) {
        Map<String, Object> map = appUserMapper.findFollowCount(userId);
        if (map != null) {
            return BaseResult.build(ResultEnum.SUCCESS);
        } else {
            return BaseResult.build(ResultEnum.FAILURE);
        }
    }

    @Override
    public BaseResult isFollow(String userId, String followId) {
        int count = appUserMapper.isFollow(userId, followId);
        if(count > 0){
            return BaseResult.build(ResultEnum.SUCCESS);
        }else{
            return BaseResult.build(ResultEnum.FAILURE);
        }
    }
}
